/*
 * panes.c
 *
 *  Created on: Nov 25, 2013
 *      Author: Ahmed
 */

#include "panes.h"
#include "nokia-5110.h"

extern pane	panels[];

/* array of "pointers to strings */
//					 12345678901234
char *panel_0[] = { "  Version 1.0 ",
					"   Copyright  ",
					"   Dec 2013   ",""};
char *panel_1[] = {	"Date and Time ",
					"Logging Mgmt  ",
					"PC Transfer   ",
					"LCD           "};
char *panel_2[] = {	"",						// Samples left
					"",						// Started / Stopped on
					" Sample Every ",
					"   xx xxxx    "};		// xx samples every min/hour/day
char *panel_3[] = {	"xx/xx/xx xx:xx",
					"","",""};
char *panel_4[] = {	"Start/Stop    ",
					"Frequency     ",
					"New Log       ",
					""};
char *panel_5[] = {	"Baud Rate 9600","","",""};
char *panel_6[] = {	"  Off after   ",
					"    xx sec    ",
					"Back Light Off",
					"    xx sec    "};
char *panel_7[] = {	"     Start    ",		// Start at x time and stop at y time
					"xx/xx/xx xx:xx",
					"     Stop     ",
					"xx/xx/xx xx:xx"};
char *panel_8[] = {"   Log every  ",		// Specify log frequency in mins/hours/days
					"    xx xxxx   ",
					"",""};
char *panel_9[] = {"Amend         ",		// New log will be stored after end of previous log
					"From Start    ","",""};// New log will be stored from start of EEPROM.
											// In all cases, once end of EEPROM is reached, the logging stops.
char *panel_10[] = {"","","",""};			// specify the serial communication status Waiting/In progress/Completed
char *panel_11[] = {"  Stop Time   ",
					"cannot be less",
					"  than start  ",
					"     time     "};
char *panel_12[] = {"  Number of   ",
					" Samples is   ",
					" greater than ",
					" storage left "};
char *panel_13[] = {"",
					" Error reading","",
					"    Sensor    "};

//						 12345678901234
char *paneTitles[] = {	"  Data Logger ",	//0
						"     Menu     ",	//1
						" Samples Left ",	//2
						" Date & Time  ",	//3
						" Logging Mgmt ",	//4
						" PC Transfer  ",	//5
						"     LCD      ",	//6
						" Log Samples  ",	//7
						"   Frequency  ",	//8
						"    New Log   ",	//9
						"    Message   "	//10
						};

//						 12345678901234						
char *paneNav[] = {		" Menu  Status ",	//0
						" Mov  Sel Bck ",	//1
						" Inc Save Next",	//2
						" Yes      Bck ",	//3
						"          Bck ",	//4
						};

pane	panels[] = {	// Index of Header, Index of Footer, Index of selection using the row# on the LCD (0xFF means no line selection)
						{0,0,0xFF,panel_0},
						{1,1,1,panel_1},
						{2,4,0xFF,panel_2},
						{3,2,0xFF,panel_3},
						{4,1,1,panel_4},
						{5,3,0xFF,panel_5},
						{6,2,0xFF,panel_6},
						{7,2,0xFF,panel_7},
						{8,2,0xFF,panel_8},
						{9,1,1,panel_9},
						{5,4,0xFF,panel_10},
						{10,4,0xFF,panel_11},			// error message
						{10,4,0xFF,panel_12},			// error message
						{10,4,0xFF,panel_13}			// error message
};

/*
 * This function displays the static 4 lines content of a panel and if
 * there is any line selection required and if so
 * will highlight it on the LCD
 */

void displayStaticPane(uint8_t paneNum){
	uint8_t	i,j;

	LCD5110_set_XY(0,0);
	LCD5110_write_string(paneTitles[panels[paneNum].pane_title_index]);
	LCD5110_set_XY(0,5);
	LCD5110_write_string(paneNav[panels[paneNum].pane_nav_index]);

	for (i = 0; i < LCD_ROWS-2; i++) {		// Header and Footer already displayed
		LCD5110_set_XY(0,i+1);
		if (*panels[paneNum].pane_body[i] == 0) {		// empty, then fill with blanks
			for (j = 0; j < LCD_COLUMNS; j++) {
				LCD5110_write_char(' ');
			}
		} else {
			LCD5110_write_string(panels[paneNum].pane_body[i]);
		}
	}

	if (panels[paneNum].last_selection_index != 0xFF && paneNum!= 7) {
					// there is a section on this panel except Panel 7 !!!
		LCD5110_set_XY(0,panels[paneNum].last_selection_index);
		LCD5110_write_string_rev(panels[paneNum].pane_body[panels[paneNum].last_selection_index-1]);
	}
}
